home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / DiskUtil / Crunch / XFH.lha / XFH / SRC / PACK.C < prev    next >
C/C++ Source or Header  |  1993-03-10  |  3KB  |  99 lines

  1. /* pack.c - packer-support routines.
  2.    Copyright (C) 1991, 1992, 1993 Kristian Nielsen.
  3.  
  4.    This file is part of XFH, the compressing file system handler.
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            */
  19.  
  20. #include "CFS.h"
  21. #include <dossupport.h>
  22.  
  23. #define MAKELONGID(a,b,c,d) \
  24. ( (ULONG)(a)<<24 | (ULONG)(b)<<16 | (ULONG)(c)<<8 | (ULONG)(d) )
  25. #define LID_PACK MAKELONGID('P','A','C','K')
  26. #ifdef NUKE_SUPPORT
  27. #define LID_NUKE MAKELONGID('N','U','K','E')
  28. #endif
  29. #ifdef POWERPACKER_SUPPORT
  30. #define LID_PP20 MAKELONGID('P','P','2','0')
  31. #endif
  32.  
  33.  
  34. #define GETID(id) xRead(glob, xfh, &(id), 4)
  35.  
  36. /* The purpose of this function is to determine what kind of file a
  37.  * (x)filehandle belongs to. Currently, this is done with a massive 'if',
  38.  * that is, it needs to be hardwired into the cfs. It would be nice to
  39.  * have a more open system - something like a list that a set of shared
  40.  * libraries could hook into, each catering for some subset of the
  41.  * supported file types.
  42.  *
  43.  * An idea would be to have an ARexx interface. Not exactly fast, but
  44.  * this way even the casual user could have the filesystem handle
  45.  * almost any file conversion through the CFS themselves! (Say, like
  46.  * converting graphics data in file format XYZZ12 from messydos machines
  47.  * to IFF).
  48.  *
  49.  */
  50. LONG xFileType( glb glob, struct FileHandle *xfh ){
  51.    LONG objtype=XOBJECT;
  52.  
  53.    /* Check for a format recognisable by longword id. */
  54.    /* (At this point in time, only XPK and XOBJ are supported). */
  55. #ifdef OBSOLETE_PRE_XPK_PACKER_SUPPORT
  56.    ULONG idbuf;
  57.  
  58.    if( GETID(idbuf) == 4) switch(idbuf){
  59.       case LID_PACK:
  60.          if( GETID(idbuf) == 4) switch( idbuf ){
  61. #ifdef NUKE_SUPPORT
  62.             case LID_NUKE:
  63.                objtype = NUKEOBJECT;
  64.                goto return_type;
  65. #endif
  66.             default:
  67.                objtype = XPKOBJECT;
  68.                goto return_type;
  69.          }
  70.          break;
  71. #ifdef POWERPACKER_SUPPORT
  72.       case LID_PP20:
  73.          objtype = PPACKOBJ;
  74.          goto return_type;
  75. #endif
  76.       default:
  77.          break;          /* Unknown main id. */
  78.    }
  79. #endif
  80.  
  81.    /* If checking for another type, remember to xSeek() if nessesary. */
  82.    debug(("Checking if file is Xpk..."));
  83.    xSeek( glob, xfh, 0L, OFFSET_BEGINNING );
  84.    if( IsXpkFile( glob, xfh )){
  85.       debug(("YES!\n"));
  86.       objtype = XPKOBJECT;
  87.       goto return_type;
  88.    }
  89.    debug(("No.\n"));
  90.    
  91.  return_type:
  92.    xSeek( glob, xfh, 0L, OFFSET_BEGINNING );
  93.    return objtype;
  94. }
  95.  
  96. #undef GETID
  97.  
  98. /* End of pack.c */
  99.